// food.js
const app = getApp();
const { pois } = require('../../utils/data.js');
const { filterPoiByType } = require('../../utils/util.js');

Page({
  data: {
    restaurants: [],
    currentDay: 0
  },

  onLoad: function () {
    // 获取所有餐厅
    const restaurants = filterPoiByType(pois, 'restaurant');
    
    this.setData({
      restaurants: restaurants
    });
  },

  // 按天数筛选
  filterByDay: function(e) {
    const day = parseInt(e.currentTarget.dataset.day);
    
    this.setData({
      currentDay: day
    });
  },

  // 查看餐厅详情
  viewRestaurantDetail: function(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/details/poi-detail?id=${id}`
    });
  },

  // 导航到餐厅
  navigateToRestaurant: function(e) {
    const id = e.currentTarget.dataset.id;
    const restaurant = this.data.restaurants.find(r => r.id === id);
    
    if (restaurant) {
      wx.openLocation({
        latitude: restaurant.position[1],
        longitude: restaurant.position[0],
        name: restaurant.name,
        address: restaurant.address || '',
        scale: 18
      });
    }
  }
}) 